package com.helloniu.wb.tools {

import com.helloniu.wb.containers.ShapeTypeDef;
import com.helloniu.fl.util.StyleTool;
import com.helloniu.fl.util.Tool;
import mx.controls.Image;
import flash.geom.Point;

public class LaserPenTool extends DrawingTool {
    public function LaserPenTool() {
        super();
        
        this.setShapeType(ShapeTypeDef.TEXT);
    }

    override protected function createChildren():void {
        super.createChildren();

        if(laserImg != null) {
            return;
        }

        laserImg = new Image();
        laserImg.source = StyleTool.getStyle("laserIcon");
        laserImg.x = 0;
        laserImg.y = 0;
        laserImg.width = 15;
        laserImg.height = 15;
        addChild(laserImg);
    }

    override public function setupListeners():void {
        // do nothing
    }

    override protected function repaint():void {
        super.repaint();

        drawLaser();
    }

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);

        drawLaser();
    }

    private function drawLaser():void {
        if(laserImg == null) {
            return;
        }

        var shapeDots:Array = getShapePoints();
        
        if(shapeDots == null || shapeDots.length == 0) {
        	return;
        }
        
        var sp:Point = shapeDots[0] as Point;
        laserImg.x = sp.x;
        laserImg.y = sp.y;
    }

    private var laserImg:Image = null;
}
}